package com.eastfair.pay.controller;

import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.core.base.R;
import com.eastfair.pay.service.StatisticsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 交易统计
 *
 * @author Du Xiaobo
 * @date 2023/6/21 14:38
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/statistics")
@Api(value = "statistics", tags = "交易记录")
@PreAuth(replace = "pay:statistics:")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;

    /**
     * 按照订单状态分组统计金额
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/card/orderStatus")
    public R orderStatusStatistics(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime,@RequestParam(value = "orderType", required = false) String orderType) {
        return R.success(statisticsService.orderStatusStatistics(startTime, endTime,orderType));
    }

    /**
     * 根据订单类型按照天分组统计
     *
     * @param startTime
     * @param endTime
     * @param orderType
     * @return
     */
    @GetMapping("/line/orderType")
    public R orderTypeStatistics(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam(value = "orderType", required = false) String orderType) {
        return R.success(statisticsService.orderTypeStatistics(startTime, endTime, orderType));
    }

    /**
     * 收入 支出 期初余额 期末余额 卡片
     *
     * @param month
     * @param payee
     * @return
     */
    @GetMapping("/card/revenueAndExpenditure")
    public R revenueAndExpenditureStatistics(@RequestParam("month") String month, @RequestParam("payee") String payee) {
        return R.success(statisticsService.revenueAndExpenditureStatistics(month, payee));
    }

    /**
     * 收入 支出 折线图
     *
     * @param month
     * @param payee
     * @param type
     * @return
     */
    @GetMapping("/line/revenueAndExpenditure")
    public R revenueAndExpenditureLineStatistics(@RequestParam("month") String month, @RequestParam("payee") String payee, @RequestParam("type") Integer type) {
        return R.success(statisticsService.revenueAndExpenditureLineStatistics(month, payee, type));
    }

}
